/**
  ******************************************************************************
  * @file    w32f006_uart.h
  * @author  WeiLink Technology 
  * @version V1.0.0
  * @date    09/01/2020
  * @brief   This file contains all the functions prototypes for the UART 
  *          firmware library.
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, WeiLink Technology SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT WeiLink Technology</center></h2>
  ******************************************************************************  
  */ 

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __W32F006_UART_H
#define __W32F006_UART_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "w32f006.h"

/** @addtogroup W32F006_StdPeriph_Driver
  * @{
  */

/** @addtogroup UART
  * @{
  */ 

/* Exported types ------------------------------------------------------------*/

/** 
  * @brief  UART Init Structure definition  
  */ 
typedef struct
{
	uint32_t UART_FEN;

	uint32_t UART_BaudRate;
	
	uint32_t UART_WordLength;          
	
	uint32_t UART_StopBits;           
	
	uint32_t UART_Parity;              
	
	uint32_t UART_SendBreak;              

	uint32_t UART_Mode;
} UART_InitTypeDef;

/* Exported constants --------------------------------------------------------*/

/** @defgroup UART_Exported_Constants
  * @{
  */ 

/** @defgroup UART_SendBreak 
  * @{
  */ 
#define UART_SendBreak_Enable               ((uint32_t)0x00000001)
#define UART_SendBreak_Disable              ((uint32_t)0x00000000)
#define IS_UART_SEND_BREAK(BREAK) 	       (((BREAK) == UART_SendBreak_Enable) || \
                                      		((BREAK) == UART_SendBreak_Disable))
/**
  * @}
  */ 
  
/** @defgroup UART_Word_Length 
  * @{
  */ 
#define UART_WordLength_5b                  ((uint32_t)0x00000000)
#define UART_WordLength_6b                  ((uint32_t)0x00000020)
#define UART_WordLength_7b                  ((uint32_t)0x00000040)
#define UART_WordLength_8b                  ((uint32_t)0x00000060)
#define IS_UART_WORD_LENGTH(LENGTH) 	   (((LENGTH) == UART_WordLength_5b) || \
                                      		((LENGTH) == UART_WordLength_6b) || \
											((LENGTH) == UART_WordLength_7b) || \
											((LENGTH) == UART_WordLength_8b))
/**
  * @}
  */ 

/** @defgroup UART_Idle_Count 
  * @{
  */ 
#define IS_UART_IDLE_COUNT(COUNT)          ((COUNT) < 16)
/**
  * @}
  */ 

/** @defgroup UART_Stop_Bits 
  * @{
  */ 
#define UART_StopBits_1                     ((uint32_t)0x00000000)
#define UART_StopBits_2                     ((uint32_t)0x00000008)
#define IS_UART_STOPBITS(STOPBITS)         (((STOPBITS) == UART_StopBits_1)   || \
                                            ((STOPBITS) == UART_StopBits_2))
/**
  * @}
  */ 

/** @defgroup UART_Parity 
  * @{
  */ 
#define UART_Parity_No                     ((uint32_t)0x00000000)
#define UART_Parity_Odd                    ((uint32_t)0x00000002)
#define UART_Parity_Even                   ((uint32_t)0x00000006)
#define UART_Parity_EPS_1                  ((uint32_t)0x00000082)
#define UART_Parity_EPS_0                  ((uint32_t)0x00000086)
 
#define IS_UART_PARITY(PARITY)            (((PARITY) == UART_Parity_No)       || \
                                            ((PARITY) == UART_Parity_Even)     || \
                                            ((PARITY) == UART_Parity_Odd)      || \
                                            ((PARITY) == UART_Parity_EPS_0)    || \
                                            ((PARITY) == UART_Parity_EPS_1))
/**
  * @}
  */ 

/** @defgroup UART_Mode 
  * @{
  */ 
#define UART_Mode_Tx                       ((uint32_t)0x00000100)
#define UART_Mode_Rx                       ((uint32_t)0x00000200)
#define IS_UART_MODE(MODE)                (((MODE) == UART_Mode_Tx) || \
                                            ((MODE) == UART_Mode_Rx) || \
                                            ((MODE) == (UART_Mode_Rx | UART_Mode_Tx)))
/**
  * @}
  */ 

/** @defgroup UART_TXIFLSEL 
  * @{
  */ 
#define UART_TXIFLSEL_2                    ((uint32_t)0x00000000)
#define UART_TXIFLSEL_4                    ((uint32_t)0x00000001)
#define UART_TXIFLSEL_8                    ((uint32_t)0x00000002)
#define UART_TXIFLSEL_12                   ((uint32_t)0x00000003)
#define UART_TXIFLSEL_14                   ((uint32_t)0x00000004)
#define IS_UART_TXIFLSEL(TXIFLSEL)		   (((TXIFLSEL) == UART_TXIFLSEL_2)  || \
                                            ((TXIFLSEL) == UART_TXIFLSEL_4)  || \
                                            ((TXIFLSEL) == UART_TXIFLSEL_8)  || \
                                            ((TXIFLSEL) == UART_TXIFLSEL_12) || \
                                            ((TXIFLSEL) == UART_TXIFLSEL_14))
/**
  * @}
  */ 

/** @defgroup UART_RXIFLSEL 
  * @{
  */ 
#define UART_RXIFLSEL_2                    ((uint32_t)0x00000000)
#define UART_RXIFLSEL_4                    ((uint32_t)0x00000008)
#define UART_RXIFLSEL_8                    ((uint32_t)0x00000010)
#define UART_RXIFLSEL_12                   ((uint32_t)0x00000018)
#define UART_RXIFLSEL_14                   ((uint32_t)0x00000020)
#define IS_UART_RXIFLSEL(RXIFLSEL)		   (((RXIFLSEL) == UART_RXIFLSEL_2)  || \
											((RXIFLSEL) == UART_RXIFLSEL_4)  || \
											((RXIFLSEL) == UART_RXIFLSEL_8)  || \
											((RXIFLSEL) == UART_RXIFLSEL_12) || \
											((RXIFLSEL) == UART_RXIFLSEL_14))
/**
  * @}
  */ 

/** @defgroup UART_FEN 
  * @{
  */ 
#define UART_FEN_Enable                     ((uint32_t)0x00000010)
#define UART_FEN_Disable                    ((uint32_t)0x00000000)
#define IS_UART_FEN(STATE)                 (((STATE) == UART_FEN_Enable) || \
                                            ((STATE) == UART_FEN_Disable))
/**
  * @}
  */

/** @defgroup UART_Interrupt_definition 
  * @{
  */
#define UART_IT_RXIM                        ((uint32_t)0x00000010)
#define UART_IT_TXIM                        ((uint32_t)0x00000020)
#define UART_IT_RTIM                        ((uint32_t)0x00000040)
#define UART_IT_FEIM                        ((uint32_t)0x00000080)
#define UART_IT_PEIM                        ((uint32_t)0x00000100)
#define UART_IT_BEIM                        ((uint32_t)0x00000200)
#define UART_IT_OEIM                        ((uint32_t)0x00000400)
#define IS_UART_CONFIG_IT(IT)              (((IT) != 0) && (((IT) & ((uint32_t)0xFFFFF80F)) == 0))

#define UART_IT_RXMIS                       ((uint32_t)0x00000010)
#define UART_IT_TXMIS                       ((uint32_t)0x00000020)
#define UART_IT_RTMIS                       ((uint32_t)0x00000040)
#define UART_IT_FEMIS                       ((uint32_t)0x00000080)
#define UART_IT_PEMIS                       ((uint32_t)0x00000100)
#define UART_IT_BEMIS                       ((uint32_t)0x00000200)
#define UART_IT_OEMIS                       ((uint32_t)0x00000400)
#define IS_UART_GET_IT(IT)                 (((IT) == UART_IT_RXMIS)   || ((IT) == UART_IT_TXMIS)   || \
                                            ((IT) == UART_IT_RTMIS)   || ((IT) == UART_IT_FEMIS)   || \
                                            ((IT) == UART_IT_PEMIS)   || ((IT) == UART_IT_BEMIS)   || \
                                            ((IT) == UART_IT_OEMIS))

#define IS_UART_CLEAR_IT(IT) 			   ((((IT) & 0x00000FF0) != 0) && (((IT) & 0xFFFFF80F) == 0))
/**
  * @}
  */

/** @defgroup UART_Flags 
  * @{
  */
#define UART_FLAG_BUSY                     ((uint32_t)0x00000008)
#define UART_FLAG_RXFE                     ((uint32_t)0x00000010)
#define UART_FLAG_TXFF                     ((uint32_t)0x00000020)
#define UART_FLAG_RXFF                     ((uint32_t)0x00000040)
#define UART_FLAG_TXFE                     ((uint32_t)0x00000080)
#define IS_UART_FLAG(FLAG)                (((FLAG) == UART_FLAG_BUSY) || \
                                           ((FLAG) == UART_FLAG_RXFE) || ((FLAG) == UART_FLAG_TXFF) || \
                                           ((FLAG) == UART_FLAG_RXFF) || ((FLAG) == UART_FLAG_TXFE))

#define IS_UART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 0x0016E361))
/**
  * @}
  */ 

/** @defgroup UART_ERRORs 
  * @{
  */
#define UART_ERROR_FE                      ((uint32_t)0x00000001)
#define UART_ERROR_PE                      ((uint32_t)0x00000002)
#define UART_ERROR_BE                      ((uint32_t)0x00000004)
#define UART_ERROR_OE                      ((uint32_t)0x00000008)
#define IS_UART_ERROR(ERROR)              (((ERROR) == UART_ERROR_FE) || ((ERROR) == UART_ERROR_PE) || \
                                           ((ERROR) == UART_ERROR_BE) || ((ERROR) == UART_ERROR_OE))
/**
  * @}
  */ 

/**
  * @}
  */ 

/* Exported macro ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
void UART_DeInit(void);
void UART_Init(UART_InitTypeDef* UART_InitStruct);
void UART_StructInit(UART_InitTypeDef* UART_InitStruct);
void UART_Cmd(FunctionalState NewState);
uint8_t UART_ReceiveData(void);
void UART_SendData(uint8_t Data);
void UART_FIFOLevelConfig(uint32_t UART_TXFL, uint32_t UART_RXFL);
void UART_RxPolarInvCmd(FunctionalState NewState);
void UART_TxPolarInvCmd(FunctionalState NewState);
FlagStatus UART_GetFlagStatus(uint32_t UART_FLAG);
FlagStatus UART_GetErrorStatus(uint32_t UART_Error);
void UART_ClearErrorStatusBit(uint32_t UART_Error);
void UART_ITConfig(uint32_t UART_IT, FunctionalState NewState);
ITStatus UART_GetITStatus(uint32_t UART_IT);
void UART_ClearITPendingBit(uint32_t UART_IT);

#ifdef __cplusplus
}
#endif

#endif /* __W32F006_UART_H */

/**
  * @}
  */ 

/**
  * @}
  */ 

/******************* (C) COPYRIGHT WeiLink Technology *****END OF FILE****/
